// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';


// 申明请求对象
const itemRequest = {
    // dict请求的基本url
    BASE_URL : confing.MD_URL + "/item",
	genWorkOrderId(callback) {
	    let url = this.BASE_URL + "/generateItemCode"
	    request.get(url, callback);
	},
	edit(mdItem,callback){
		let url = this.BASE_URL + "/update";
		request.put(url,mdItem,callback);
	},
	selectById(itemId,callback){
		let url = this.BASE_URL + "/get?itemId=" + itemId;
		request.get(url,callback);
	},
    /**
     * 保存字典信息
     * @param {*} item 
     * @param {*} callback 
     */
    save(item,callback){
        if(item){
            request.post(this.BASE_URL + "/save",item,callback);
        }
    },
    // 请求的API
    list(page = 1,limit = 10,item,callbcak){
        // url
        let url = this.BASE_URL + "/list?page=" + page + "&limit=" + limit;
        if(item){
            if(item.itemTypeName){
                url += "&itemTypeName=" + item.itemTypeName;
            }
            if(item.itemCode){
                url += "&itemCode=" + item.itemCode;
            }
            if(item.itemName){
                url += "&itemName=" + item.itemName;
            }
			if(item.itemOrProduct){
			    url += "&itemOrProduct=" + item.itemOrProduct;
			}
			if(item.itemTypeId){
			    url += "&itemTypeId=" + item.itemTypeId;
			}
			
        }
        // 发送请求
        request.get(url,callbcak);
    }
}

// 将dictRequest暴漏出去
export default itemRequest;